/*
 * @Author: hongbin
 * @Date: 2022-12-02 10:48:57
 * @LastEditors: hongbin
 * @LastEditTime: 2022-12-24 09:55:52
 * @Description:适用于本项目的助手
 */

class CanRunClass {
    /**
     * 正在输入中 这时键盘控制人物移动暂停
     */
    inputting = false;

    startInput() {
        this.inputting = true;
    }

    endInput() {
        this.inputting = false;
    }
}

export const CanRun = new CanRunClass();

class LoadProcessClass {
    _onCanShow = () => {};

    onCanShow = (call: VoidFunction) => {
        this._onCanShow = call;
    };

    canShow() {
        this._onCanShow();
    }
}

export const LoadProcess = new LoadProcessClass();

/**
 * 截取用户名以显示
 * 英文数字结合显示两个字符
 * 中文和特殊字符显示一个字符
 */
export const UserNameSlice = (username: string) => {
    const reg = new RegExp(/^[a-z|A-Z|0-9][a-z|A-Z|0-9]/);
    const slice = username.slice(0, 2);
    if (reg.test(slice)) return slice;
    return slice[0];
};
